package com.qiaofang.collectmanage.service.common.utils;

import com.alibaba.fastjson.JSONObject;
import com.qiaofang.collectmanage.base.configuration.CollectManageConfiguration;
import com.qiaofang.collectmanage.service.common.bean.MetricInfo;
import com.qiaofang.collectmanage.service.common.constant.ConstantProperties;
import com.qiaofang.collectmanage.service.common.constant.MetricsCons;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IDEA
 *
 * @author:ZJ.J
 * @Date:2018/6/14
 * @Time:16:23
 */
public class MetricUtils {
    public static void send(String metric){
        String url = CollectManageConfiguration.getMetricsTsdbUrl();
        Map<String, String> tags = new HashMap<>(4);
        tags.put("appname", "crawler");
        MetricInfo metricInfo = new MetricInfo();
        metricInfo.setMetric(metric);
        metricInfo.setTimestamp(System.currentTimeMillis());
        metricInfo.setValue(1);
        metricInfo.setTags(tags);
        HttpClientUtils.httpPostWithJson((JSONObject) JSONObject.toJSON(metricInfo), url);
    }

    public static void main(String[] args) {
        for(int i = 0; i < 10000; i++){
            send(MetricsCons.HTTP_REQUEST_OUT);
        }

    }
}
